var app = getApp()
Page({

  data: {
    item: [],
    isShowConfirm: false,
    score: 0,
    tips: "",
    isFine: false,
    ismark: true,
    modalHidden: true,
    isHave:false 
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '面试打分'
    })
    var postId = options.postid
    this.setData({
      item: app.globalData.interview[postId],
      avatar : app.globalData.interview[postId].avatar
    })
    if(this.data.avatar != null){
      this.setData({
        isHave : true
      })
    }
    if(this.data.item.isPass1 == 1){
      this.setData({
        reason : app.globalData.interview[postId].reason1
      })
    }else {
      this.setData({
        reason : app.globalData.interview[postId].reason2
      })
    }
  },

  OnMark_FinishTap: function (event) {
    var that = this
    var score = this.data.score
    wx.redirectTo({
      url: '/pages/interview/interview',
    })

    //判断是否通过面试
    if (this.data.score < 60 && that.data.item.isPass1 == 1) {
      that.data.item.isPass1 = 0
      that.data.item.isUsed = 1
      that.data.item.score = parseFloat(that.data.score)
      that.data.item.isOut = 1
      that.data.item.tips = that.data.tips
      that.data.item.isPass = 0
      var i
      for (i = 0; i < app.globalData.sum; i++) {
        if (app.globalData.data[i].id == that.data.item.id) {
          app.globalData.data[i].score = score
          app.globalData.data[i].isPass1 = 0
          app.globalData.data[i].isUsed = 1
          app.globalData.data[i].isOut = 1 
          app.globalData.data[i].isPass = 0
          app.globalData.data[i].tips =  that.data.tips
        }
      }
      // 更新知晓云数据项  分数 ，备注 ， 是否通过第一志愿
      let tableName = 'data'
      let recordID = that.data.item.id

      let Product = new wx.BaaS.TableObject(tableName)
      let product = Product.getWithoutData(recordID)

      product.set('score', parseFloat(score))
      product.set('tips', that.data.tips)
      product.set('isPass1', 0)
      product.set('isUsed', 1)
      product.set('isOut', 1)
      product.set('isPass', 0)
      product.update().then(res => {
        console.log(res)
      }, err => {
        // err
      })
    }
    else if (this.data.score < 60 && that.data.item.isPass1 == 0 && that.data.item.isOut == 1) {
      that.data.item.score = parseFloat(that.data.score)
      that.data.item.isPass2 = 0
      that.data.item.isOut = 1
      that.data.item.isUsed = 1
      that.data.item.isPass = 0
      that.data.item.tips = that.data.tips
      var i
      for (i = 0; i < app.globalData.sum; i++) {
        if (app.globalData.data[i].id == that.data.item.id) {
          app.globalData.data[i].score = score
          app.globalData.data[i].isPass2 = 0
          app.globalData.data[i].isUsed = 1
          app.globalData.data[i].isOut = 1
          app.globalData.data[i].isPass = 0
          app.globalData.data[i].tips =  that.data.tips
        }
      }
      // 更新知晓云数据项  分数 ，备注 ， 是否通过第一志愿
      let tableName = 'data'
      let recordID = that.data.item.id

      let Product = new wx.BaaS.TableObject(tableName)
      let product = Product.getWithoutData(recordID)

      product.set('score', parseFloat(score))
      product.set('tips', that.data.tips)
      product.set('isPass2', 0)
      product.set('isUsed', 1)
      product.set('isOut', 1)
      product.set('isPass', 0)
      product.update().then(res => {
        console.log(res)
      }, err => {
        // err
      })
    }

    if (this.data.score >= 60 && that.data.item.isPass1 == 1) {
      that.data.item.score = parseFloat(that.data.score)
      that.data.item.tips = that.data.tips
      that.data.item.isUsed = 1
      var i
      for (i = 0; i < app.globalData.sum; i++) {
        if (app.globalData.data[i].id == that.data.item.id) {
          app.globalData.data[i].score = score
          app.globalData.data[i].tips =  that.data.tips
          app.globalData.data[i].isUsed = 1
        }
      }
      // 更新知晓云数据项  分数 ，备注 ， 是否通过第一志愿
      let tableName = 'data'
      let recordID = that.data.item.id

      let Product = new wx.BaaS.TableObject(tableName)
      let product = Product.getWithoutData(recordID)

      product.set('score', parseFloat(score))
      product.set('tips', that.data.tips)
      product.set('isUsed', 1)
      product.update().then(res => {
        console.log(res)
      }, err => {
        // err
      })
    }
    if (this.data.score >= 60 && that.data.item.isPass1 == 0) {
      that.data.item.score = parseFloat(that.data.score)
      that.data.item.tips = that.data.tips
      that.data.item.isUsed = 1
      var i
      for (i = 0; i < app.globalData.sum; i++) {
        if (app.globalData.data[i].id == that.data.item.id) {
          app.globalData.data[i].score = score
          app.globalData.data[i].tips = that.data.tips
          app.globalData.data[i].isUsed = 1
        }
      }
      // 更新知晓云数据项  分数 ，备注 ， 是否通过第一志愿
      let tableName = 'data'
      let recordID = that.data.item.id

      let Product = new wx.BaaS.TableObject(tableName)
      let product = Product.getWithoutData(recordID)

      product.set('score', parseFloat(score))
      product.set('tips', that.data.tips)
      product.set('isUsed', 1)
      product.update().then(res => {
        console.log(res)
      }, err => {
        // err
      })
    }
  },

  OnMarkTap: function (event) {
    var that = this
    that.setData({
      isShowConfirm: true,
      ismark: false
    })
  },

  tipsInput: function (e) {
    this.setData({
      tips: e.detail.value
    })
  },

  setValue: function (e) {
    var i
    var that = this
    this.setData({
      score: e.detail.value
    })
    if (this.data.score <= 100 && this.data.score >= 0) {
      this.setData({
        isFine: true
      })
      for (i = 0; i < app.globalData.sum; i++) {
        if (app.globalData.data[i].id == that.data.item.id) {
          app.globalData.data[i].score = e.detail.value
        }
      }
    }
  },

  setTips: function (e) {
    var that = this
    var tips = e.detail.value
    console.log(tips)
    var i
    for (i = 0; i < app.globalData.sum; i++) {
      if (app.globalData.data[i].id == that.data.item.id) {
        app.globalData.data[i].tips = tips
        this.data.tips = tips
      }
    }
  },

  cancel: function () {
    var that = this
    that.setData({
      isShowConfirm: false,
      ismark: true
    })
  },

  confirmAcceptance: function () {
    var that = this
    that.setData({
      isShowConfirm: false,
      ismark: true
    })
  },

  //展开详细信息
  Oninformation_reason:function(e){
    this.setData({
      modalHidden: false,
      ismark: false
    })
  },
   /**
   * 点击取消
   */
  modalCandel: function () {
    // do something
    this.setData({
      modalHidden: true,
      ismark: true
    })
  },

  /**
   *  点击确认
   */
  modalConfirm: function () {
    // do something
    this.setData({
      modalHidden: true,
      ismark: true
    })
  },
  
})